package org.fanximall.erp.system.infrastructure.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.fanximall.erp.system.infrastructure.convert.DeptConverter;
import org.fanximall.erp.system.infrastructure.dao.entity.SysDeptDO;
import org.fanximall.erp.system.infrastructure.dao.mapper.SysDeptMapper;
import org.fanximall.erp.system.domain.model.SysDeptModel;
import org.fanximall.erp.system.domain.repository.SysDeptRepository;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @author :  william
 * @version :  V1.0  created in 2024/4/19
 */
@Repository
public class SysDeptRepositoryImpl implements SysDeptRepository {

    @Resource
    private SysDeptMapper deptMapper;
    @Override
    public List<SysDeptModel> listAllDept(String deptName,Integer status) {
        LambdaQueryWrapper<SysDeptDO> sysDeptDOLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(sysDeptDOLambdaQueryWrapper)) {
            sysDeptDOLambdaQueryWrapper.like(SysDeptDO::getDeptName, deptName);
        }
        if (!ObjectUtils.isEmpty(status)) {
            sysDeptDOLambdaQueryWrapper.eq(SysDeptDO::getStatus, status);
        }
        List<SysDeptDO> sysDeptDOS = deptMapper.selectList(sysDeptDOLambdaQueryWrapper);
        return CollectionUtils.isEmpty(sysDeptDOS) ? Collections.emptyList() : DeptConverter.INSTANCE.convertModel(sysDeptDOS);
    }
}
